package com.ttdev.mmms.service.impl;

import com.ttdev.mmms.entity.MemberInfo;
import com.ttdev.mmms.repository.MemberLoginRepository;
import com.ttdev.mmms.service.MemberLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * 用户名和密码判断层 王旭国
 */
@Service
public class MemberLoginServiceImpl implements MemberLoginService {

    @Autowired
    private MemberLoginRepository loginRepository;

    public MemberInfo queryAll(String username, String password) {
        List<MemberInfo> list = loginRepository.queryAll();
        MemberInfo member = null;
        String name1 = null, name2 = null, pwd1 = null;
        Integer name3 = null;
        for (int i = 0; i < list.size(); i++) {
            member = list.get(i);
            name1 = member.getName();
            name2 = member.getIphone();
            name3 = member.getCardId();
            pwd1 = member.getPassword();
            if (username.equals(name1)) {
                break;
            }
        }
        if ((username.equals(name1) || username.equals(name2) || username.equals(name3)) && password.equals(pwd1)) {
            return member;
        } else {
            System.out.println("用户名或者密码为空");
            return null;

        }

    }
}